<?php

namespace App\Http\Controllers;

use App\Http\Requests\PasswordRequset;
use Illuminate\Http\Request;

class PasswordController extends Controller
{

    public function __construct()
    {
        $this->middleware('check');
    }

    //
    public function changePassword(){
        return view('home.index.password');
    }
    public function password(Request $request,PasswordRequset $passwordRequset){
        //获取post数据
        $post = $request->all();
//        dd($post);
        //获取旧数据
        $user = \Auth::user();
        $user->username = $post['username'];
        //判断密码是否填写，如果填写了 修改密码
        if($post['password']){
            $user->password = bcrypt($post['password']);
        }
        $user->save();
        session()->flash('success','修改成功');
        return redirect('/index');
    }
}
